<template>
  <div class="microApp_a">
    <template v-if="is_url">
      <micro-app name="microApp" :url="is_url" @datachange="handleDataChange" :data="datainfo"></micro-app>
    </template>
  </div>
</template>
<script>
export default {
  data() {
    return {
      datainfo: {
        group_id:''
      },
      is_url:""
    };
  },
  activated() {
    // this.getData();
    // console.log(this.fun.getKey('group_id'),'dwwwwwww')
    // console.log(process.env.NODE_ENV)
    this.is_url =  process.env.NODE_ENV == 'development'?'http://localhost:8080/':this.fun.getSiteRoot()+"/addons/yun_shop/child/im/index.html"
    console.log(this.is_url);
    if(this.fun.getKey('group_id')){
      console.log('页面链接有group_id',this.fun.getKey('group_id'))
      this.datainfo.group_id = this.fun.getKey('group_id');
    }
  },
  methods: {
    handleDataChange(_data) {
      console.log("dddddddddddddddddd", _data.detail.data.TapType);
      if(_data.detail.data.TapType == "pageCurrentInd"){
        let ind = _data.detail.data.ind;
        if(ind == '0'){
          this.fun.setWXTitle('消息')
        }else if(ind == '1'){
          this.fun.setWXTitle('通讯录')
        }else if(ind){
          this.fun.setWXTitle('我的')
        }
      }
      if (_data.detail.data.TapType == "scan_YDB") {
        // 子应用调用扫一扫
        console.log("子应用调用扫一扫");
        YDB.GetScan("scanCodeParams");
      } else if(_data.detail.data.TapType == "login"){
        this.$dialog.alert({ message: `请登录`})
        .then(() => {
          // console.log("子应用提示需要跳转商城登录页面");
          window.location.href = this.fun.getSiteRoot() + "/addons/yun_shop/" + "?menu#" + "/login?i=" + this.fun.getKeyByI() + "&type=" + this.fun.getTyep() ;
          sessionStorage.setItem('yz_redirect',this.fun.getSiteRoot()+"/addons/yun_shop/#/microApp_a?i="+this.fun.getKeyByI());
        })
        return
      } else if (_data.detail.data.TapType == "fail_404"){
        console.log("子应用提示需要跳转商城404页面");
        window.location.href = Fun.getSiteRoot() + "/addons/yun_shop/" + "?menu#" + "/404?i=" + Fun.getKeyByI();
        return
      } else if (_data.detail.data.TapType == "closeYdbScroll"){
        // console.log('YDB.SetDragRefresh(0)0000000000000000000000')
        YDB.SetDragRefresh(0);
      } else if (_data.detail.data.TapType == "openYdbScroll"){
        // console.log('YDB.SetDragRefresh(1)1111111111111111111111')
        YDB.SetDragRefresh(1)
      }
    },
    // scanCodeParams(val) {
    //   console.log("子应用调用扫一扫scanCodeParams", val);
    //   window.location.href = val;
    // },
    getData() {
      $http
        .get("plugin.instant-message.frontend.controllers.index.user-sig", {}, "生成中")
        .then(response => {
          if (response.result === 1) {
            this.datainfo = response.data;
          } else {
            this.$dialog.alert({
              message: response.msg
            });
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>

